package com.peanut.baby.model;

import com.google.gson.annotations.SerializedName;
import com.peanut.devlibrary.util.JsonUtils;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by anonymouslystudio on 2017/8/23.
 */

public class DailySign {

    public int userId;
    public String date;

    @SerializedName("xDays")
    public int xDays;
    @SerializedName("yPoints")
    public int yPoints;
    @SerializedName("message")
    public String message;
    @SerializedName("userPoint")
    public int userPoint;
    @SerializedName("variedPoint")
    public int variedPoint;
    @SerializedName("totalPoint")
    public int totalPoint;

    public void parseDBCache(String content){
        try {
            JSONObject obj = new JSONObject(content);
            xDays = JsonUtils.JSONInter(obj,"xDays");
            yPoints = JsonUtils.JSONInter(obj,"yPoints");
            userPoint = JsonUtils.JSONInter(obj,"userPoint");
            variedPoint = JsonUtils.JSONInter(obj,"variedPoint");
            totalPoint = JsonUtils.JSONInter(obj,"totalPoint");
            message = JsonUtils.JSONString(obj,"message");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public String toDBCache(){
        JSONObject obj = new JSONObject();
        try {
            obj.put("xDays",xDays);
            obj.put("yPoints",yPoints);
            obj.put("userPoint",userPoint);
            obj.put("variedPoint",variedPoint);
            obj.put("totalPoint",totalPoint);
            obj.put("message",message);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return obj.toString();
    }
}
